package br.com.localfloripa.dao;

import java.util.List;

import javax.inject.Named;
import javax.persistence.Query;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import br.com.localfloripa.entities.Ramo;

@Named("ramoDao")
public class RamoDao extends DaoManager<Ramo> {

	private static final Logger log = LoggerFactory.getLogger(RamoDao.class);
	
	public Ramo findById(Long idRamo) throws Exception {
		return em.find(Ramo.class, idRamo);
	}
	
	public List<Ramo> listRamosPaginada(int first,int pageSize) throws Exception {
		
		Query query = em.createQuery("SELECT r FROM Ramo r ORDER BY r.nome");
		query.setFirstResult(first);
		query.setMaxResults(pageSize);		
		return query.getResultList();
	}
	
	public Long countListRamos() {
		Query query = em.createQuery("SELECT COUNT(r.id) FROM Ramo r");
		return (Long) query.getSingleResult();
	}
	
	public List<Ramo> listRamosOrdemNome() throws Exception {
		Query query = em.createQuery("SELECT r FROM Ramo r WHERE r.ativo IS TRUE ORDER BY r.nome");
		return query.getResultList();
	}

}
